﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using nspKnow;

public partial class Member_Know_KnowProblemsAdd : nspBase.MemberBasePge
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (CheckCookies())
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }
        else
            Response.Redirect("../../login/login.aspx");
    }
    private void Bind()
    {
        listType1.Items.Add(new ListItem("--+选择+--", "0"));
        listType2.Items.Add(new ListItem("--+选择+--", "0"));
        KnowType know = new KnowType();
        DataTable dt = know.GetDataTable("where ParentID=0");

        if (dt.Rows.Count != 0)
        {
            foreach (DataRow dataRow in dt.Rows)
            {

                listType1.Items.Add(new ListItem(dataRow["Name"].ToString(), dataRow["ID"].ToString()));

            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string Restr = "";
        KnowProblem problem = new KnowProblem();
        if (txtCaption.Text.Trim().Equals(string.Empty))
            Restr += "问题标题、";
        else
            problem.Caption = txtCaption.Text.Trim();
        if (txtDetail.Text.Trim().Equals(string.Empty))
            Restr += "问题补充说明、";
        else
            problem.Detail = txtDetail.Text.Trim();
        if (listType1.SelectedValue == "0" || listType1.SelectedValue == "")
        {
            Restr += "请选择类别、";
        }
        else
        {
            if (listType2.SelectedValue == "0" || listType2.SelectedValue == "")
                problem.TypeID = int.Parse(this.listType1.SelectedValue);
            else
                problem.TypeID = int.Parse(this.listType2.SelectedValue);
        }
        problem.UserID = int.Parse(GetCookie("UserID"));
        problem.UserName = GetCookie("LoginName");
        problem.AddDate = DateTime.Now;
        if (Restr != "")
            Restr = Restr.TrimEnd('、');
        if (Restr.Equals(string.Empty))
        {
            problem.Insert(problem);
            ShowMessage("提问成功！", "Know/ProblemsList.aspx");

        }
        else
        {
            lblMessage.Visible = true;
            lblMessage.Text = Restr + "填写有误！";
        }
    }
    protected void listType1_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            if (listType1.SelectedValue != "0")
            {
                string strWhere = "where ParentID=";
                listType2.Items.Clear();
                listType2.Items.Add(new ListItem("--选择类--", "0"));
                KnowType know = new KnowType();
                strWhere += listType1.SelectedValue;
                DataTable dt = know.GetDataTable(strWhere);
                if (dt.Rows.Count != 0)
                {
                    foreach (DataRow dataRow in dt.Rows)
                    {

                        listType2.Items.Add(new ListItem(dataRow["Name"].ToString(), dataRow["ID"].ToString()));

                    }
                }
            }
        }
        catch (Exception ex)
        {
            ShowMessage(ex.Message);
        }
    }

}
